package edu.scau.mis.rest.service.impl;

import edu.scau.mis.rest.entity.RestGroupDiscount;
import edu.scau.mis.rest.mapper.RestGroupDiscountMapper;
import edu.scau.mis.rest.service.RestGroupDiscountService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * (RestGroupDiscount)表服务实现类
 *
 * @author makejava
 * @since 2022-03-15 20:50:52
 */
@Service("restGroupDiscountService")
public class RestGroupDiscountServiceImpl implements RestGroupDiscountService {
    @Resource
    private RestGroupDiscountMapper restGroupDiscountMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public RestGroupDiscount queryById(Long id) {
        return this.restGroupDiscountMapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param restGroupDiscount 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<RestGroupDiscount> queryByPage(RestGroupDiscount restGroupDiscount, PageRequest pageRequest) {
        long total = this.restGroupDiscountMapper.count(restGroupDiscount);
        return new PageImpl<>(this.restGroupDiscountMapper.queryAllByLimit(restGroupDiscount, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param restGroupDiscount 实例对象
     * @return 实例对象
     */
    @Override
    public RestGroupDiscount insert(RestGroupDiscount restGroupDiscount) {
        this.restGroupDiscountMapper.insert(restGroupDiscount);
        return restGroupDiscount;
    }

    /**
     * 修改数据
     *
     * @param restGroupDiscount 实例对象
     * @return 实例对象
     */
    @Override
    public RestGroupDiscount update(RestGroupDiscount restGroupDiscount) {
        this.restGroupDiscountMapper.update(restGroupDiscount);
        return this.queryById(restGroupDiscount.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.restGroupDiscountMapper.deleteById(id) > 0;
    }

    /**
     * 套餐全查询
     *
     * @return
     */
    @Override
    public List<RestGroupDiscount> queryAll(){return this.restGroupDiscountMapper.queryAll();}

    /**
     * 根据套餐证号查询该套餐
     *
     * @param groupDiscountNo
     * @return
     */
    @Override
    public RestGroupDiscount queryGroupDiscountByNo(String groupDiscountNo){return this.restGroupDiscountMapper.queryGroupDiscountByNo(groupDiscountNo);}
}
